import { createRouter, createWebHashHistory } from 'vue-router'
import store from '../store'
const routes = [
  {
    path: '/',
    redirect: '/find'
  },
  {
    path: '/find',
    name: 'Find',
    component: () => import('../views/Find.vue')
  },
  {
    path: '/recommended',
    name: 'recommended',
    component: () => import('../components/Find/recommended.vue')
  },
  {
    path: '/listView',
    name: 'listView',
    component: () => import('../views/listView.vue')
  },
  {
    path: '/me',
    name: 'me',
    beforeEnter: (to, from, next) => {
      if (store.state.user.isLogin) {
        next()
      } else {
        next('login')
      }
    },
    component: () => import('../views/Me.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/allMusic',
    name: 'allMusic',
    component: () => import('../components/Find/allMusic.vue')
  },
  {
    path: '/singer',
    name: 'singer',
    component: () => import('../components/Find/singer.vue')
  },
  {
    path: '/singerHomepage',
    name: 'singerHomepage',
    component: () => import('../components/Find/singerHomepage.vue')
  },
  {
    path: '/specialAlbum',
    name: 'specialAlbum',
    component: () => import('../components/Find/specialAlbum.vue')
  },
  {
    path: '/mvList',
    name: 'mvList',
    component: () => import('../components/Find/mvList.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/Search.vue')
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

export default router
